<template>
    <el-form :model="Form" ref="Form" label-width="100px">
        <el-form-item label="姓名" prop="name">
            <el-input v-model="Form.name"></el-input>
        </el-form-item>

        <el-form-item label="时间">
            <el-col :span="3">
                <el-form-item prop="time">
                    <el-date-picker type="date" v-model="Form.time" style="width: 100%;"></el-date-picker>
                </el-form-item>
            </el-col>
        </el-form-item>
        <el-form-item label="状态" prop="status">
            <el-switch v-model="Form.status" :active-value="1"></el-switch>
        </el-form-item>
        <el-form-item label="身份" prop="major">
            <el-radio-group v-model="Form.major">
                <el-radio label="管理员"></el-radio>
                <el-radio label="普通用户"></el-radio>
            </el-radio-group>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="onSubmit()">提交更改</el-button>
            <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>
    </el-form>
</template>

<script>
    export default {
        name: "update",
        data() {
            return {
                Form: {}
            }
        },
        methods: {
            onSubmit() {
                this.$http.put('/api/users/' + this.$route.params.id, this.Form)
                .then(({data, config}) => {
                    console.log(data, config)
                    if (data.code == 200) {
                        this.$message({
                            message: '修改成功！',
                            type: 'success'
                        })
                    } else {
                        this.$message({
                            message: '修改失败！',
                            type: 'warning'
                        })
                    }
                })
            },
            resetForm(formName) {
                this.$refs[formName].resetFields();
            }
        },
        mounted() {
            this.$http.get('/api/users/' + this.$route.params.id)
            .then(({data}) => {
                if (data.code == 200) {
                    this.Form = data.data[0]
                }
            })
        }
    }
</script>

<style scoped>

</style>